let departmentAddMoudle=(function(){
    let $infoBox=$('.infoBox'),
    $form=$('.form'),
    $userdepartment=$('.userdepartment'),
    $saydepartment=$('saydepartment'),
    $submit=$('.submit');
    let departmentId=null;

    //从服务器获取部门的基本信息，绑定在对应的文本框中

    async function queryBaseInfo(){
        let result= await axios.get('/department/info'，{
            params:{
                departmentId
            }
        });
        if(result.code==0){
            result=result.data;
            $userdepartment.val(result.name);
            $saydepartment.val(result.desc);
            return;
        };
        alert('小主，当前要编辑的部门不存在，请查证！');
        departmentId=null;
    }

     // 点击确认提交按钮
     async function submitHandle(){
        //重复表单校验
        //获取用户输入的信息
        let params={
            name:$userdepartment.val(),
          
            desc:$saydepartment.val()
        }


        //向服务器发送请求（区分新增还是修改）
        if(departmentId){
            //xiugai
            params.departmentId=departmentId;
            let result= await axios.post('/department/update',params);
                if(result.code==0){
                    alert('小主，您很棒，已成功修改一条数据');
                    window.location.href="departmentlist.html";
                    return;
                }
                alert('小主，当前网络繁忙，稍后再试');
            return;


        }
        // /新增
        let result= await axios.post('/department/add',params);
        if(result.code==0){
            alert('小主，您很棒，已成功新增一条数据');
            window.location.href="departmentlist.html";
            return;
        }
        alert('小主，当前网络繁忙，稍后再试');
    }


    return {
        init(){
          $submit.click(submitHandle);
        }
    }
})();
departmentAddMoudle.init();